package com.jiawei.mapper;

import com.jiawei.entity.database.Menu;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/**
 * @author : willian fu
 * @date : 2019/12/11
 */
public interface MenuMapper extends Mapper<Menu> {

    /**
     * 根据userID查询用户可见菜单
     * @param userId
     * @return 菜单列表
     */
    @Select("SELECT menu.* FROM user_role AS ur  " +
            "LEFT JOIN role_menu AS rm ON ur.role_id = rm.role_id " +
            "LEFT JOIN menu ON rm.menu_id = menu.id " +
            "WHERE ur.user_id = #{userId}")
    List<Menu> getMenusByUser(@Param("userId") Long userId);
}
